//
//  ModelDetailViewController.m
//  CheXunWang
//
//  Created by zhu lin on 12/25/11.
//  Copyright 2011 Zhulin. All rights reserved.
//

#import "ModelDetailViewController.h"
#import "StorageService.h"
#import "HttpServices.h"
#import "CustomBarButtonItem.h"
#import "ImageListViewController.h"
#import "SBJSON.h"

#define kDefaultSectionNum		1
#define kDefaultCellNum			1
#define kCustomSectionHeight	20.0
#define kCustomCellHeight		30.0
#define kCustomBlankCellHeight	269.0

#define kModelID				@"modelId"
#define kModelName				@"modelName"
#define kModelGuidePrice		@"guidePrice"
#define kModelGuidePriceFor4S	@"guidePriceFor4S"
#define kModelImagePath			@"imagePath"

#define kPropertyNameTag		1001
#define kPropertyValueTag		1002

@interface ModelDetailViewController()
@property (nonatomic, retain) NSMutableDictionary		*modelDetailDic;
@property (nonatomic, retain) ASIHTTPRequest			*modelImageRequest;
@property (nonatomic, retain) ASIHTTPRequest			*modelDetailRequest;
@property (nonatomic, retain) ASIHTTPRequest			*photoCountRequest;

- (void)initPropertyMap;
- (NSString *)getValueOfKey:(NSString *)keyName;
- (void)popViewController:(id)sender;
- (void)loadModelInfo;
- (UIImage *)loadModelImage;
- (void)loadModelDetail;
- (void)loadPhotoCount;
@end

/*
 [
	 {
	 "length": 3400,
	 "modelId": 5135,
	 "maxSpeed": 120.0,
	 "speededUp": null,
	 "brakeTest": null,
	 "fuelConsumption": null,
	 "combinedConsumption": 6.4,
	 "qualityAssurance": "三年或8万公里",
	 "width": 1575,
	 "height": 1670,
	 "wheelbase": 2335,
	 "frontTrack": 1360,
	 "rearTrack": 1355,
	 "minDisforfloor": 163,
	 "weight": 900,
	 "structure": "两厢车",
	 "doors": 5,
	 "seats": 5,
	 "tankVolume": 42.0,
	 "trunkVolume": "630",
	 "engineModel": null,
	 "cylinderVolume": 970,
	 "displacement": 1.0,
	 "workType": "自然吸气",
	 "cylinderForm": "L",
	 "cylinderNum": 4,
	 "valvesNum": 2,
	 "compressRatio": 8.8,
	 "valveStructure": "DOHC",
	 "bore": 65.5,
	 "stroke": 72.0,
	 "maxHorsepower": "46",
	 "maxPower": "33.5",
	 "maxPowerSpeed": "5000",
	 "maxTorque": "72",
	 "maxTorqueSpeed": "3000-3500",
	 "engineEchnology": null,
	 "fuelType": "汽油",
	 "fuelLabel": "93号",
	 "fuelWay": "多点电喷",
	 "cylinderHeadMaterial": "铝",
	 "cylinderBodyMaterial": "铝",
	 "epStandards": "国IV",
	 "gearNum": "5",
	 "transmissionType": "手动变速箱(MT)",
	 "drive": "前置前驱",
	 "frontSuspension": "麦弗逊式独立悬架",
	 "rearSuspension": "非独立单纵摆臂式",
	 "powerType": "无助力",
	 "bodyStructure": "承载式",
	 "frontBrake": "盘式",
	 "rearBrake": "鼓式",
	 "parkingBrake": "手刹",
	 "frontTire": "165/65 R13",
	 "rearTire": "165/65 R13",
	 "spareTire": "全尺寸",
	 "seatAirbag": "0",
	 "copilotAirbag": "0",
	 "frontSideAirbag": "0",
	 "rearSideAirbag": "0",
	 "frontHeadAirbag": "0",
	 "rearHeadAirbag": "0",
	 "kneeAirbag": "0",
	 "tpMonitorDevice": "0",
	 "zeroTpTravel": "0",
	 "seatBeltTips": "0",
	 "engineSecurity": "1",
	 "centralLock": "0",
	 "remoteKey": "0",
	 "keylessStartSystem": "0",
	 "absAntiLock": "0",
	 "brakingForceDistribution": "0",
	 "brakeAssist": "0",
	 "tractionControl": "0",
	 "stabilityControl": "0",
	 "autoParking": "0",
	 "hillDescent": "0",
	 "adjustableSuspension": "0",
	 "airSuspension": "0",
	 "activeSteering": "0",
	 "electricSunroof": "0",
	 "panoramicSunroof": "0",
	 "sportsPackage": "0",
	 "alloyWheels": "0",
	 "electricDoor": "0",
	 "coriumWheel": "0",
	 "wheelUd": "0",
	 "wheelFr": "0",
	 "wheelElectric": "0",
	 "multifunctionWheel": "0",
	 "wheelShift": "0",
	 "cruise": "0",
	 "parkAssist": "0",
	 "reverseVideo": "0",
	 "rripComputerDisplay": "0",
	 "hudDigitalDisplay": "0",
	 "coriumSimulationSeat": "0",
	 "sportSeat": "0",
	 "seatHl": "0",
	 "waistSupport": "0",
	 "shoulderSupport": "0",
	 "frontSeatElectric": "0",
	 "secondBackAngle": "1",
	 "secondSeatMove": "0",
	 "rearSeatElectric": "0",
	 "electricSeatMemory": "0",
	 "frontSeatHeating": "0",
	 "rearSeatHeating": "0",
	 "seatAiriness": "0",
	 "seatMassage": "0",
	 "rearSeatOverall": "1",
	 "rearSeatRatio": "0",
	 "thirdSeat": "0",
	 "frontCenterArmrest": "0",
	 "rearCenterArmrest": "0",
	 "rearCupHolder": "0",
	 "electricTrunk": "0",
	 "gpsNavigateSystem": "0",
	 "locateInteractionService": "0",
	 "centerColorScreen": "0",
	 "humanComputerSystem": "0",
	 "hardDrive": "0",
	 "bluetoothPhone": "0",
	 "carTv": "0",
	 "rearLcdScreen": "0",
	 "externalAudioInterfaces": "0",
	 "cdSupportMp3": "0",
	 "singleCd": "0",
	 "virtualMultiCd": "0",
	 "multiCdSystem": "0",
	 "singleDvd": "0",
	 "multiDvdSystem": "0",
	 "twoSpeakerSystem": "1",
	 "fourSpeakerSystem": "0",
	 "sixSpeakerSystem": "0",
	 "eightSpeakerSystem": "0",
	 "xenonLight": "0",
	 "daytimeRunningLight": "0",
	 "autoHeadlight": "0",
	 "steeringHeadlight": "0",
	 "frontFogLight": "1",
	 "lightHeight": "0",
	 "lightCleanDevice": "0",
	 "atmosphereLight": "0",
	 "frontPowerWindow": "0",
	 "rearPowerWindow": "0",
	 "windowAntiTrapHand": "0",
	 "uvInsulatedGlass": "0",
	 "rearviewElectric": "0",
	 "rearviewHeating": "0",
	 "rearviewAutoAntiGlare": "0",
	 "rearviewElectricFold": "0",
	 "rearviewMemory": "0",
	 "rearWindShadeCurtain": "0",
	 "rearShadeCurtain": "0",
	 "shadeMirror": "1",
	 "rearWiper": "0",
	 "sensingWipers": "0",
	 "manualAir": "1",
	 "autoAir": "0",
	 "rearIndependentAir": "0",
	 "rearOutlet": "0",
	 "temperatureZoneControl": "0",
	 "airControlPollenFilter": "0",
	 "carRefrigerator": "0",
	 "autoParkingPlace": "0",
	 "andLineAuxiliary": "0",
	 "activeBrake": "0",
	 "overallActiveSystem": "0",
	 "nightSystem": "0",
	 "controlLcdScreen": "0",
	 "adaptiveCruise": "0",
	 "panoramicCamera": "0"
	 }
 ]
 */

@implementation ModelDetailViewController
@synthesize modelImageView;
@synthesize imageCountLabel;
@synthesize priceLabel;
@synthesize priceFor4SLabel;
@synthesize favoriteButton;
@synthesize modelDetailTableView;

@synthesize modelInfoDic;
@synthesize modelDetailDic;
@synthesize modelImageRequest;
@synthesize modelDetailRequest;
@synthesize photoCountRequest;

static NSMutableDictionary *propertyMap;

#pragma mark -
#pragma mark lifecycle
/*
 基础参数
 车身参数
 发动机参数
 变速箱参数
 底盘转向参数
 车轮制动
 安全装备
 控制配置
 外部配置
 内部配置
 座椅配置
 多媒体配置
 灯光配置
 玻璃/后视镜
 空调/冰箱
 高科技配置
 */
 

- (void)initPropertyMap
{
	propertyMap = [[NSMutableDictionary alloc] init];
	
	[propertyMap setValue:@"长度(mm)" forKey:@"length"];
	[propertyMap setValue:@"最高车速（km/h）" forKey:@"maxSpeed"];
	[propertyMap setValue:@"官方0-100加速（s）" forKey:@"speededUp"];
	[propertyMap setValue:@"实测100-0制动（m）" forKey:@"brakeTest"];
	[propertyMap setValue:@"实测油耗（L）" forKey:@"fuelConsumption"];
	[propertyMap setValue:@"工信部综合油耗（L）" forKey:@"combinedConsumption"];
	[propertyMap setValue:@"整车质保" forKey:@"qualityAssurance"];
	[propertyMap setValue:@"宽度(mm)" forKey:@"width"];
	[propertyMap setValue:@"高度(mm)" forKey:@"height"];
	[propertyMap setValue:@"轴距(mm)" forKey:@"wheelbase"];
	[propertyMap setValue:@"前轮距(mm)" forKey:@"frontTrack"];
	[propertyMap setValue:@"后轮距(mm)" forKey:@"rearTrack"];
	[propertyMap setValue:@"最小离地间隙(mm)" forKey:@"minDisforfloor"];
	[propertyMap setValue:@"整备质量(Kg)" forKey:@"weight"];
	[propertyMap setValue:@"车身结构" forKey:@"structure"];
	[propertyMap setValue:@"车门数(个)" forKey:@"doors"];
	[propertyMap setValue:@"座位数(个)" forKey:@"seats"];
	[propertyMap setValue:@"油箱容积(L)" forKey:@"tankVolume"];
	[propertyMap setValue:@"行李箱容积(L)" forKey:@"trunkVolume"];
	[propertyMap setValue:@"发动机型号" forKey:@"engineModel"];
	[propertyMap setValue:@"汽缸容积(cc)" forKey:@"cylinderVolume"];
	[propertyMap setValue:@"排量(L)" forKey:@"displacement"];
	[propertyMap setValue:@"工作方式" forKey:@"workType"];
	[propertyMap setValue:@"汽缸排列形式" forKey:@"cylinderForm"];
	[propertyMap setValue:@"汽缸数(个)" forKey:@"cylinderNum"];
	[propertyMap setValue:@"每缸气门数(个)" forKey:@"valvesNum"];
	[propertyMap setValue:@"压缩比" forKey:@"compressRatio"];
	[propertyMap setValue:@"气门结构" forKey:@"valveStructure"];
	[propertyMap setValue:@"缸径" forKey:@"bore"];
	[propertyMap setValue:@"冲程" forKey:@"stroke"];
	[propertyMap setValue:@"最大马力(Ps)" forKey:@"maxHorsepower"];
	[propertyMap setValue:@"最大功率(kW)" forKey:@"maxPower"];
	[propertyMap setValue:@"最大功率转速(rpm)" forKey:@"maxPowerSpeed"];
	[propertyMap setValue:@"最大扭矩(N·m)" forKey:@"maxTorque"];
	[propertyMap setValue:@"最大扭矩转速(rpm)" forKey:@"maxTorqueSpeed"];
	[propertyMap setValue:@"发动机特有技术" forKey:@"engineEchnology"];
	[propertyMap setValue:@"燃料形式" forKey:@"fuelType"];
	[propertyMap setValue:@"燃油标号" forKey:@"fuelLabel"];
	[propertyMap setValue:@"供油方式" forKey:@"fuelWay"];
	[propertyMap setValue:@"缸盖材料" forKey:@"cylinderHeadMaterial"];
	[propertyMap setValue:@"缸体材料" forKey:@"cylinderBodyMaterial"];
	[propertyMap setValue:@"环保标准" forKey:@"epStandards"];
	[propertyMap setValue:@"挡位个数" forKey:@"gearNum"];
	[propertyMap setValue:@"变速箱类型" forKey:@"transmissionType"];
	[propertyMap setValue:@"驱动方式" forKey:@"drive"];
	[propertyMap setValue:@"前悬挂类型" forKey:@"frontSuspension"];
	[propertyMap setValue:@"后悬挂类型" forKey:@"rearSuspension"];
	[propertyMap setValue:@"助力类型" forKey:@"powerType"];
	[propertyMap setValue:@"车体结构" forKey:@"bodyStructure"];
	[propertyMap setValue:@"前制动器类型" forKey:@"frontBrake"];
	[propertyMap setValue:@"后制动器类型" forKey:@"RearBrake"];
	[propertyMap setValue:@"驻车制动类型" forKey:@"parkingBrake"];
	[propertyMap setValue:@"前轮胎规格" forKey:@"frontTire"];
	[propertyMap setValue:@"后轮胎规格" forKey:@"rearTire"];
	[propertyMap setValue:@"备胎规格" forKey:@"spareTire"];
	[propertyMap setValue:@"驾驶座安全气囊" forKey:@"seatAirbag"];
	[propertyMap setValue:@"副驾驶安全气囊" forKey:@"copilotAirbag"];
	[propertyMap setValue:@"前排侧气囊" forKey:@"frontSideAirbag"];
	[propertyMap setValue:@"后排侧气囊" forKey:@"rearSideAirbag"];
	[propertyMap setValue:@"前排头部气囊(气帘)" forKey:@"frontHeadAirbag"];
	[propertyMap setValue:@"后排头部气囊(气帘)" forKey:@"rearHeadAirbag"];
	[propertyMap setValue:@"膝部气囊" forKey:@"kneeAirbag"];
	[propertyMap setValue:@"胎压监测装置" forKey:@"tpMonitorDevice"];
	[propertyMap setValue:@"零胎压继续行驶" forKey:@"zeroTpTravel"];
	[propertyMap setValue:@"安全带未系提示" forKey:@"seatBeltTips"];
	[propertyMap setValue:@"发动机电子防盗" forKey:@"engineSecurity"];
	[propertyMap setValue:@"车内中控锁" forKey:@"centralLock"];
	[propertyMap setValue:@"遥控钥匙" forKey:@"remoteKey"];
	[propertyMap setValue:@"无钥匙启动系统" forKey:@"keylessStartSystem"];
	[propertyMap setValue:@"ABS防抱死" forKey:@"absAntiLock"];
	[propertyMap setValue:@"制动力分配(EBD/CBC等)" forKey:@"brakingForceDistribution"];
	[propertyMap setValue:@"刹车辅助(EBA/BAS/BA等)" forKey:@"brakeAssist"];
	[propertyMap setValue:@"牵引力控制(ASR/TCS/TRC等)" forKey:@"tractionControl"];
	[propertyMap setValue:@"车身稳定控制(ESP/DSC/VSC等)" forKey:@"stabilityControl"];
	[propertyMap setValue:@"自动驻车/上坡辅助" forKey:@"autoParking"];
	[propertyMap setValue:@"陡坡缓降" forKey:@"hillDescent"];
	[propertyMap setValue:@"可调悬挂" forKey:@"adjustableSuspension"];
	[propertyMap setValue:@"空气悬挂" forKey:@"airSuspension"];
	[propertyMap setValue:@"主动转向系统" forKey:@"activeSteering"];
	[propertyMap setValue:@"电动天窗" forKey:@"electricSunroof"];
	[propertyMap setValue:@"全景天窗" forKey:@"panoramicSunroof"];
	[propertyMap setValue:@"运动外观套件" forKey:@"sportsPackage"];
	[propertyMap setValue:@"铝合金轮毂" forKey:@"alloyWheels"];
	[propertyMap setValue:@"电动吸合门" forKey:@"electricDoor"];
	[propertyMap setValue:@"真皮方向盘" forKey:@"coriumWheel"];
	[propertyMap setValue:@"方向盘上下调节" forKey:@"wheelUd"];
	[propertyMap setValue:@"方向盘前后调节" forKey:@"wheelFr"];
	[propertyMap setValue:@"方向盘电动调节" forKey:@"wheelElectric"];
	[propertyMap setValue:@"多功能方向盘" forKey:@"multifunctionWheel"];
	[propertyMap setValue:@"方向盘换挡" forKey:@"wheelShift"];
	[propertyMap setValue:@"定速巡航" forKey:@"cruise"];
	[propertyMap setValue:@"泊车辅助" forKey:@"parkAssist"];
	[propertyMap setValue:@"倒车视频影像" forKey:@"reverseVideo"];
	[propertyMap setValue:@"行车电脑显示屏" forKey:@"rripComputerDisplay"];
	[propertyMap setValue:@"HUD抬头数字显示" forKey:@"hudDigitalDisplay"];
	[propertyMap setValue:@"真皮/仿皮座椅" forKey:@"coriumSimulationSeat"];
	[propertyMap setValue:@"运动座椅" forKey:@"sportSeat"];
	[propertyMap setValue:@"座椅高低调节" forKey:@"seatHl"];
	[propertyMap setValue:@"腰部支撑调节" forKey:@"waistSupport"];
	[propertyMap setValue:@"肩部支撑调节" forKey:@"shoulderSupport"];
	[propertyMap setValue:@"前排座椅电动调节" forKey:@"frontSeatElectric"];
	[propertyMap setValue:@"第二排靠背角度调节" forKey:@"secondBackAngle"];
	[propertyMap setValue:@"第二排座椅移动" forKey:@"secondSeatMove"];
	[propertyMap setValue:@"后排座椅电动调节" forKey:@"rearSeatElectric"];
	[propertyMap setValue:@"电动座椅记忆" forKey:@"electricSeatMemory"];
	[propertyMap setValue:@"前排座椅加热" forKey:@"frontSeatHeating"];
	[propertyMap setValue:@"后排座椅加热" forKey:@"rearSeatHeating"];
	[propertyMap setValue:@"座椅通风" forKey:@"seatAiriness"];
	[propertyMap setValue:@"座椅按摩" forKey:@"seatMassage"];
	[propertyMap setValue:@"后排座椅整体放倒" forKey:@"rearSeatOverall"];
	[propertyMap setValue:@"后排座椅比例放倒" forKey:@"rearSeatRatio"];
	[propertyMap setValue:@"第三排座椅" forKey:@"thirdSeat"];
	[propertyMap setValue:@"前座中央扶手" forKey:@"frontCenterArmrest"];
	[propertyMap setValue:@"后座中央扶手" forKey:@"rearCenterArmrest"];
	[propertyMap setValue:@"后排杯架" forKey:@"rearCupHolder"];
	[propertyMap setValue:@"电动后备箱" forKey:@"electricTrunk"];
	[propertyMap setValue:@"GPS导航系统" forKey:@"gpsNavigateSystem"];
	[propertyMap setValue:@"定位互动服务" forKey:@"locateInteractionService"];
	[propertyMap setValue:@"中控台彩色大屏" forKey:@"centerColorScreen"];
	[propertyMap setValue:@"人机交互系统" forKey:@"humanComputerSystem"];
	[propertyMap setValue:@"内置硬盘" forKey:@"hardDrive"];
	[propertyMap setValue:@"蓝牙/车载电话" forKey:@"bluetoothPhone"];
	[propertyMap setValue:@"车载电视" forKey:@"carTv"];
	[propertyMap setValue:@"后排液晶屏" forKey:@"rearLcdScreen"];
	[propertyMap setValue:@"外接音源接口(AUX/USB/iPod等)" forKey:@"externalAudioInterfaces"];
	[propertyMap setValue:@"CD支持MP3/WMA" forKey:@"cdSupportMp3"];
	[propertyMap setValue:@"单碟CD" forKey:@"singleCd"];
	[propertyMap setValue:@"虚拟多碟CD" forKey:@"virtualMultiCd"];
	[propertyMap setValue:@"多碟CD系统" forKey:@"multiCdSystem"];
	[propertyMap setValue:@"单碟DVD" forKey:@"singleDvd"];
	[propertyMap setValue:@"多碟DVD系统" forKey:@"multiDvdSystem"];
	[propertyMap setValue:@"2-3喇叭扬声器系统" forKey:@"twoSpeakerSystem"];
	[propertyMap setValue:@"4-5喇叭扬声器系统" forKey:@"fourSpeakerSystem"];
	[propertyMap setValue:@"6-7喇叭扬声器系统" forKey:@"sixSpeakerSystem"];
	[propertyMap setValue:@"≥8喇叭扬声器系统" forKey:@"eightSpeakerSystem"];
	[propertyMap setValue:@"氙气大灯" forKey:@"xenonLight"];
	[propertyMap setValue:@"日间行车灯" forKey:@"daytimeRunningLight"];
	[propertyMap setValue:@"自动头灯" forKey:@"autoHeadlight"];
	[propertyMap setValue:@"转向头灯(辅助灯)" forKey:@"steeringHeadlight"];
	[propertyMap setValue:@"前雾灯" forKey:@"frontFogLight"];
	[propertyMap setValue:@"大灯高度可调" forKey:@"lightHeight"];
	[propertyMap setValue:@"大灯清洗装置" forKey:@"lightCleanDevice"];
	[propertyMap setValue:@"车内氛围灯" forKey:@"atmosphereLight"];
	[propertyMap setValue:@"前电动车窗" forKey:@"frontPowerWindow"];
	[propertyMap setValue:@"后电动车窗" forKey:@"rearPowerWindow"];
	[propertyMap setValue:@"车窗防夹手功能" forKey:@"windowAntiTrapHand"];
	[propertyMap setValue:@"防紫外线/隔热玻璃" forKey:@"uvInsulatedGlass"];
	[propertyMap setValue:@"后视镜电动调节" forKey:@"rearviewElectric"];
	[propertyMap setValue:@"后视镜加热" forKey:@"rearviewHeating"];
	[propertyMap setValue:@"后视镜自动防眩目" forKey:@"rearviewAutoAntiGlare"];
	[propertyMap setValue:@"后视镜电动折叠" forKey:@"rearviewElectricFold"];
	[propertyMap setValue:@"后视镜记忆" forKey:@"rearviewMemory"];
	[propertyMap setValue:@"后风挡遮阳帘" forKey:@"rearWindShadeCurtain"];
	[propertyMap setValue:@"后排侧遮阳帘" forKey:@"rearShadeCurtain"];
	[propertyMap setValue:@"遮阳板化妆镜" forKey:@"shadeMirror"];
	[propertyMap setValue:@"后雨刷" forKey:@"rearWiper"];
	[propertyMap setValue:@"感应雨刷" forKey:@"sensingWipers"];
	[propertyMap setValue:@"手动空调" forKey:@"manualAir"];
	[propertyMap setValue:@"自动空调" forKey:@"autoAir"];
	[propertyMap setValue:@"后排独立空调" forKey:@"rearIndependentAir"];
	[propertyMap setValue:@"后座出风口" forKey:@"rearOutlet"];
	[propertyMap setValue:@"温度分区控制" forKey:@"temperatureZoneControl"];
	[propertyMap setValue:@"空气调节/花粉过滤" forKey:@"airControlPollenFilter"];
	[propertyMap setValue:@"车载冰箱" forKey:@"carRefrigerator"];
	[propertyMap setValue:@"自动泊车入位" forKey:@"autoParkingPlace"];
	[propertyMap setValue:@"并线辅助" forKey:@"andLineAuxiliary"];
	[propertyMap setValue:@"主动刹车/主动安全系统" forKey:@"activeBrake"];
	[propertyMap setValue:@"整体主动转向系统" forKey:@"overalActiveSystem"];
	[propertyMap setValue:@"夜视系统" forKey:@"nightSystem"];
	[propertyMap setValue:@"中控液晶屏分屏显示" forKey:@"controlLcdScreen"];
	[propertyMap setValue:@"自适应巡航" forKey:@"adaptiveCruise"];
	[propertyMap setValue:@"panoramicCamera" forKey:@"全景摄像头"];
	
	/*
	"length": 3400,
	"modelId": 5135,
	"maxSpeed": 120.0,
	"speededUp": null,
	"brakeTest": null,
	"fuelConsumption": null,
	"combinedConsumption": 6.4,
	"qualityAssurance": "三年或8万公里",
	"width": 1575,
	"height": 1670,
	"wheelbase": 2335,
	"frontTrack": 1360,
	"rearTrack": 1355,
	"minDisforfloor": 163,
	"weight": 900,
	"structure": "两厢车",
	"doors": 5,
	"seats": 5,
	"tankVolume": 42.0,
	"trunkVolume": "630",
	"engineModel": null,
	"cylinderVolume": 970,
	"displacement": 1.0,
	"workType": "自然吸气",
	"cylinderForm": "L",
	"cylinderNum": 4,
	"valvesNum": 2,
	"compressRatio": 8.8,
	"valveStructure": "DOHC",
	"bore": 65.5,
	"stroke": 72.0,
	"maxHorsepower": "46",
	"maxPower": "33.5",
	"maxPowerSpeed": "5000",
	"maxTorque": "72",
	"maxTorqueSpeed": "3000-3500",
	"engineEchnology": null,
	"fuelType": "汽油",
	"fuelLabel": "93号",
	"fuelWay": "多点电喷",
	"cylinderHeadMaterial": "铝",
	"cylinderBodyMaterial": "铝",
	"epStandards": "国IV",
	"gearNum": "5",
	"transmissionType": "手动变速箱(MT)",
	"drive": "前置前驱",
	"frontSuspension": "麦弗逊式独立悬架",
	"rearSuspension": "非独立单纵摆臂式",
	"powerType": "无助力",
	"bodyStructure": "承载式",
	"frontBrake": "盘式",
	"rearBrake": "鼓式",
	"parkingBrake": "手刹",
	"frontTire": "165/65 R13",
	"rearTire": "165/65 R13",
	"spareTire": "全尺寸",
	"seatAirbag": "0",
	"copilotAirbag": "0",
	"frontSideAirbag": "0",
	"rearSideAirbag": "0",
	"frontHeadAirbag": "0",
	"rearHeadAirbag": "0",
	"kneeAirbag": "0",
	"tpMonitorDevice": "0",
	"zeroTpTravel": "0",
	"seatBeltTips": "0",
	"engineSecurity": "1",
	"centralLock": "0",
	"remoteKey": "0",
	"keylessStartSystem": "0",
	"absAntiLock": "0",
	"brakingForceDistribution": "0",
	"brakeAssist": "0",
	"tractionControl": "0",
	"stabilityControl": "0",
	"autoParking": "0",
	"hillDescent": "0",
	"adjustableSuspension": "0",
	"airSuspension": "0",
	"activeSteering": "0",
	"electricSunroof": "0",
	"panoramicSunroof": "0",
	"sportsPackage": "0",
	"alloyWheels": "0",
	"electricDoor": "0",
	"coriumWheel": "0",
	"wheelUd": "0",
	"wheelFr": "0",
	"wheelElectric": "0",
	"multifunctionWheel": "0",
	"wheelShift": "0",
	"cruise": "0",
	"parkAssist": "0",
	"reverseVideo": "0",
	"rripComputerDisplay": "0",
	"hudDigitalDisplay": "0",
	"coriumSimulationSeat": "0",
	"sportSeat": "0",
	"seatHl": "0",
	"waistSupport": "0",
	"shoulderSupport": "0",
	"frontSeatElectric": "0",
	"secondBackAngle": "1",
	"secondSeatMove": "0",
	"rearSeatElectric": "0",
	"electricSeatMemory": "0",
	"frontSeatHeating": "0",
	"rearSeatHeating": "0",
	"seatAiriness": "0",
	"seatMassage": "0",
	"rearSeatOverall": "1",
	"rearSeatRatio": "0",
	"thirdSeat": "0",
	"frontCenterArmrest": "0",
	"rearCenterArmrest": "0",
	"rearCupHolder": "0",
	"electricTrunk": "0",
	"gpsNavigateSystem": "0",
	"locateInteractionService": "0",
	"centerColorScreen": "0",
	"humanComputerSystem": "0",
	"hardDrive": "0",
	"bluetoothPhone": "0",
	"carTv": "0",
	"rearLcdScreen": "0",
	"externalAudioInterfaces": "0",
	"cdSupportMp3": "0",
	"singleCd": "0",
	"virtualMultiCd": "0",
	"multiCdSystem": "0",
	"singleDvd": "0",
	"multiDvdSystem": "0",
	"twoSpeakerSystem": "1",
	"fourSpeakerSystem": "0",
	"sixSpeakerSystem": "0",
	"eightSpeakerSystem": "0",
	"xenonLight": "0",
	"daytimeRunningLight": "0",
	"autoHeadlight": "0",
	"steeringHeadlight": "0",
	"frontFogLight": "1",
	"lightHeight": "0",
	"lightCleanDevice": "0",
	"atmosphereLight": "0",
	"frontPowerWindow": "0",
	"rearPowerWindow": "0",
	"windowAntiTrapHand": "0",
	"uvInsulatedGlass": "0",
	"rearviewElectric": "0",
	"rearviewHeating": "0",
	"rearviewAutoAntiGlare": "0",
	"rearviewElectricFold": "0",
	"rearviewMemory": "0",
	"rearWindShadeCurtain": "0",
	"rearShadeCurtain": "0",
	"shadeMirror": "1",
	"rearWiper": "0",
	"sensingWipers": "0",
	"manualAir": "1",
	"autoAir": "0",
	"rearIndependentAir": "0",
	"rearOutlet": "0",
	"temperatureZoneControl": "0",
	"airControlPollenFilter": "0",
	"carRefrigerator": "0",
	"autoParkingPlace": "0",
	"andLineAuxiliary": "0",
	"activeBrake": "0",
	"overallActiveSystem": "0",
	"nightSystem": "0",
	"controlLcdScreen": "0",
	"adaptiveCruise": "0",
	"panoramicCamera": "0"
	*/
}

- (NSString *)getValueOfKey:(NSString *)keyName
{
	if ([self.modelDetailDic count] > 0) {
		id value = [self.modelDetailDic valueForKey:keyName];
		if (!value || [value isEqual:[NSNull null]]) {
			return @"-";
		}
		if ([value isKindOfClass:[NSNumber class]]) {
			return [value stringValue];
		}
		if ([value isEqualToString:@"0"]) {
			return @"无";
		}
		if ([value isEqualToString:@"1"]) {
			return @"有";
		}	 
		return (NSString *)value;
	}
	return @"";
}
 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.navigationItem.hidesBackButton = YES;
	CustomBarButtonItem *backButton = [[CustomBarButtonItem alloc] initWithTitle:@"返回" style:LeftBarButtonItemBackStyle target:self action:@selector(popViewController:)];
	self.navigationItem.leftBarButtonItem = backButton;
	[backButton release];
	self.modelDetailTableView.tableFooterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 0)] autorelease];
	
	self.modelDetailDic = [NSMutableDictionary dictionary];
	[self initPropertyMap];
	[self loadModelInfo];
	[self loadModelDetail];
	[self loadPhotoCount];
}

- (void)popViewController:(id)sender
{	
	[self.navigationController popViewControllerAnimated:YES];
}


- (void)loadModelInfo
{
	if (self.modelInfoDic != nil) {
		if ([self.modelInfoDic objectForKey:kModelGuidePrice] && ![[self.modelInfoDic objectForKey:kModelGuidePrice] isEqual:[NSNull null]]) {
			self.priceLabel.text = [[self.modelInfoDic objectForKey:kModelGuidePrice] stringValue];
		} else {
			self.priceLabel.text = @"未知";
		}

		self.priceFor4SLabel.text = (NSString *)[self.modelInfoDic valueForKey:kModelGuidePriceFor4S];
		self.modelImageView.image = [self loadModelImage];
	}
}

- (void)loadModelDetail
{
	if (self.modelInfoDic != nil) {
		self.modelDetailRequest = [HttpServices getModelDetailByModelID:[[self.modelInfoDic objectForKey:kModelID] stringValue] delegate:self];
	}
}

- (void)loadPhotoCount
{
	if (self.modelInfoDic != nil) {
		self.photoCountRequest = [HttpServices getCarPhotoCountBySeriesId:nil modelId:[[self.modelInfoDic objectForKey:kModelID] stringValue] andDelegate:self];
	}
}

- (UIImage *)loadModelImage
{
	if (self.modelInfoDic != nil)
	{
		NSString *imageURL = (NSString *)[self.modelInfoDic valueForKey:kModelImagePath];
		NSString *imageName = (NSString *)[[imageURL componentsSeparatedByString:@"/"] lastObject];
		NSString *imagePath = [StorageService getPathByStorageType:ZLStorageTypeSeriesImage withFileName:imageName];
		
		if ([[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
			return [UIImage imageWithContentsOfFile:imagePath];
		} else {
			if (self.modelImageRequest == nil) {
				self.modelImageRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:imageURL]];
				[self.modelImageRequest setDelegate:self];
				[self.modelImageRequest setDownloadDestinationPath:imagePath];
				[self.modelImageRequest startAsynchronous];
			}
		}
	}
	
	return [UIImage imageNamed:@"ios_common_list_item_avatar.png"];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[self.modelImageRequest clearDelegatesAndCancel];
	[self.modelDetailRequest clearDelegatesAndCancel];
	[self.photoCountRequest clearDelegatesAndCancel];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
	[self.modelDetailDic removeAllObjects];
	[self.modelImageRequest clearDelegatesAndCancel];
	self.modelImageRequest = nil;
	[self.modelDetailRequest clearDelegatesAndCancel];
	self.modelDetailRequest = nil;
	[self.photoCountRequest clearDelegatesAndCancel];
	self.photoCountRequest = nil;
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
	self.modelImageView = nil;
	self.imageCountLabel = nil;
	self.priceLabel = nil;
	self.priceFor4SLabel = nil;
	self.modelDetailTableView = nil;
	
	self.modelImageRequest = nil;
	self.modelDetailRequest = nil;
	self.photoCountRequest = nil;
}

- (void)dealloc {
	[photoCountRequest release];
	[modelImageRequest release];
	[modelDetailRequest release];
	[modelImageView release];
	[imageCountLabel release];
	[priceLabel release];
	[priceFor4SLabel release];
	[modelDetailDic release];
	[modelInfoDic release];
    [super dealloc];
}

#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return kDefaultSectionNum;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	if ([self.modelDetailDic count] == 0) {
		return kDefaultCellNum;
	}
	
    return [propertyMap count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	if ([self.modelDetailDic count] == 0) {
		return kCustomBlankCellHeight;
	}
	
	return kCustomCellHeight;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
	if ([self.modelDetailDic count] == 0) {
		return nil;
	}
	
	UIView *customSectionView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, kCustomSectionHeight)];
	UIImageView *backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ios_common_list_title_bg.png"]];
	backImageView.frame = CGRectMake(0.0, 0.0, 320.0, kCustomSectionHeight);
	[customSectionView addSubview:backImageView];
	[backImageView release];
	UILabel *companyLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 0.0f, 300.0f, kCustomSectionHeight)];
	companyLabel.backgroundColor = [UIColor clearColor];
	companyLabel.textColor = [UIColor colorWithRed: 0.2 green: 0.2 blue: 0.2 alpha: 1.0];
	companyLabel.font = [UIFont systemFontOfSize:12.0f];
	companyLabel.text = @"详细参数";
	[customSectionView addSubview:companyLabel];
	[companyLabel release];
	return customSectionView;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *blankCellIdentifier = @"blankCell";
	static NSString *modelPropertyCellIdentifier = @"modelPropertyCell";
    
	if ([self.modelDetailDic count] == 0) {
		UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:blankCellIdentifier];
        if (cell == nil)
		{
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
										   reuseIdentifier:blankCellIdentifier] autorelease];
			cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
		return cell;
	}
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:modelPropertyCellIdentifier];
    if (cell == nil)
	{
		cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:modelPropertyCellIdentifier];
		cell.selectionStyle = UITableViewCellSelectionStyleNone;
		cell.contentView.backgroundColor = [UIColor clearColor];
		
		// add propertyName
		UILabel *propertyNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 0.0, 150.0f, kCustomCellHeight)];
		propertyNameLabel.backgroundColor = [UIColor clearColor];
		propertyNameLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
		propertyNameLabel.textAlignment = UITextAlignmentLeft;
		propertyNameLabel.font = [UIFont systemFontOfSize:13.0];
		propertyNameLabel.textColor = [UIColor colorWithRed:29.0/255.0 green:29.0/255.0 blue:29.0/255.0 alpha:1.0];
		propertyNameLabel.tag = kPropertyNameTag;
		[cell.contentView addSubview:propertyNameLabel];
		[propertyNameLabel release];
		
		// add propertyValue
		UILabel *propertyValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(160.0f, 0.0, 140.0f, kCustomCellHeight)];
		propertyValueLabel.backgroundColor = [UIColor clearColor];
		propertyValueLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
		propertyValueLabel.textAlignment = UITextAlignmentLeft;
		propertyValueLabel.font = [UIFont systemFontOfSize:13.0];
		propertyValueLabel.textColor = [UIColor colorWithRed:29.0/255.0 green:29.0/255.0 blue:29.0/255.0 alpha:1.0];
		propertyValueLabel.tag = kPropertyValueTag;
		[cell.contentView addSubview:propertyValueLabel];
		[propertyValueLabel release];
	}
    
    // Configure the cell...
	UILabel *propertyNameLabel = (UILabel *)[cell.contentView viewWithTag:kPropertyNameTag];
	UILabel *propertyValueLabel = (UILabel *)[cell.contentView viewWithTag:kPropertyValueTag];
	
	NSString *propertyKey = (NSString *)[[propertyMap allKeys] objectAtIndex:indexPath.row];
	propertyNameLabel.text = (NSString *)[propertyMap valueForKey:propertyKey];
	propertyValueLabel.text = [self getValueOfKey:propertyKey];
	
    return cell;
}

#pragma mark -
#pragma mark ASIHTTPRequestDelegate methods
- (void)requestFinished:(ASIHTTPRequest *)request
{
	if (request == self.modelImageRequest) {
		self.modelImageView.image = [self loadModelImage];
	} else if (request ==  self.modelDetailRequest){
		//
		NSData *responseData = [request responseData];
		NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
		self.modelDetailDic = (NSMutableDictionary *)[(NSArray *)[result JSONValue] objectAtIndex:0];
		//NSLog(@"result:%@\n detail count:%d\n property count:%d",result, [self.modelDetailDic count], [propertyMap count]);
		
		[self.modelDetailTableView reloadData];
	} else {
		NSData *responseData = [request responseData];
		NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
		//[{"imageCount":31}]
		NSString *count = [[(NSDictionary *)[(NSArray *)[result JSONValue] objectAtIndex:0] valueForKey:@"imageCount"] stringValue];
		self.imageCountLabel.text = [NSString stringWithFormat:@"%@张图片",count];
	}
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
	if (request = self.modelImageRequest) {
		self.modelImageView.image = [self loadModelImage];
	} else {
		//
	}
}

#pragma mark -
#pragma mark actions
- (void)handleFavorite:(id)sender
{
	
}

- (IBAction)show4SLocation:(id)sender
{
	
}

- (IBAction)showImageList:(id)sender
{
	ImageListViewController *imageListVC = [[ImageListViewController alloc] init];
	imageListVC.modelID = [[self.modelInfoDic valueForKey:kModelID] stringValue];
	imageListVC.title = [self.modelInfoDic valueForKey:kModelName];
	imageListVC.hidesBottomBarWhenPushed = YES;
	[self.navigationController pushViewController:imageListVC animated:YES];
	[imageListVC release];
}

- (IBAction)addForCompare:(id)sender
{
	
}

- (IBAction)gotoCalculator:(id)sender
{
	
}
@end
